package operation;

import result.Score;
import result.ScoreList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(ScoreList scoreList) {
        System.out.println("新添学生成绩！！！");
        Scanner sc=new Scanner(System.in);
        System.out.println("输入学生姓名:");
        String name=sc.nextLine();
        System.out.println("输入学生学号:");
        String studentID=sc.nextLine();
        System.out.println("输入课程名称:");
        String courseName=sc.nextLine();
        System.out.println("输入成绩:");
        int score=sc.nextInt();
        int sizex=scoreList.getSize()+1;
        Score score1=new Score(sizex,name,studentID,courseName,score);
        sizex++;
        int size=scoreList.getSize();
        for(int i=0;i<size;i++){
            Score score2=scoreList.getScores(i);
            if(score2.getName().equals(name)&&score2.getStudentID().equals(studentID)&&score2.getCourseName().equals(courseName)){
                System.out.println("该学生成绩已存在，请重新输入！");
                return;
            }
        }
        if(scoreList.getScores().length ==size){
            System.out.println("成绩列表满了");
        }else{
            scoreList.setScores(size,score1);
            scoreList.setSize(size+1);
        }
    }
}
